package com.systemCapacity.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.systemCapacity.common.dto.BattlePlatformDeviceDto;
import com.systemCapacity.entity.BattlePlatformDevice;
import com.systemCapacity.mapper.BattlePlatformDeviceMapper;
import com.systemCapacity.service.BattlePlatformDeviceService;
import com.systemCapacity.service.DeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class BattlePlatformDeviceServiceImpl extends ServiceImpl<BattlePlatformDeviceMapper, BattlePlatformDevice> implements BattlePlatformDeviceService{

    @Autowired
    DeviceService deviceService;

    @Override
    public void saveBattlePlatformDevice(List<BattlePlatformDeviceDto> battlePlatformDeviceDtoList){
        for (BattlePlatformDeviceDto battlePlatformDeviceDto : battlePlatformDeviceDtoList) {
            BattlePlatformDevice battlePlatformDevice = new BattlePlatformDevice();
            BeanUtil.copyProperties(battlePlatformDeviceDto,battlePlatformDevice);
            battlePlatformDevice.setId(UUID.randomUUID().toString());
            save(battlePlatformDevice);
        }
    }

    @Override
    public void deletePlatformDeviceByPlatformIdList(List<String> platformIdList){
        for (String platformId : platformIdList) {
            QueryWrapper<BattlePlatformDevice> battlePlatformDeviceQueryWrapper = new QueryWrapper<>();
            battlePlatformDeviceQueryWrapper.eq("platformId",platformId);
            List<BattlePlatformDevice> battlePlatformDeviceList = list(battlePlatformDeviceQueryWrapper);
            for (BattlePlatformDevice battlePlatformDevice : battlePlatformDeviceList) {
                removeById(battlePlatformDevice.getId());
//                deviceService.deleteIfNotExists(battlePlatformDevice.getDeviceId());
            }
        }
    }

    @Override
    public List<BattlePlatformDevice> queryPlatformDeviceByCapacityId(String capacityId){
        QueryWrapper<BattlePlatformDevice> battlePlatformDeviceQueryWrapper = new QueryWrapper<>();
        battlePlatformDeviceQueryWrapper.eq("capacityId",capacityId);
        return list(battlePlatformDeviceQueryWrapper);
    }
}
